﻿//********************************************************************************//
//创建日期：<创建日期，2016-02-26>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：区县办公室
//********************************************************************************//
using System;
using System.Web.UI;
using Entity;
using BLL;
using System.Data;
using Web.Class;

namespace Web.Pages.YongShui.JiChuXX
{
    public partial class QuXianBGS : BasePage
    {
        #region 属性

        /// <summary>
        ///当前操作项ID
        /// </summary>
        private int QuXianBGSID
        {
            get
            {
                return Convert.ToInt32(ViewState["_QuXianBGSID"]);
            }
            set
            {
                ViewState["_QuXianBGSID"] = value;
            }
        }

        /// <summary>
        /// 保存结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 区县办公室对象
        /// </summary>
        YS_JX_QUXIANBGS _YS_JX_QUXIANBGS = new YS_JX_QUXIANBGS();

        /// <summary>
        /// 区县办公室BLL
        /// </summary>
        YS_JX_QUXIANBGSBLL _YS_JX_QUXIANBGSBLL = new YS_JX_QUXIANBGSBLL();

        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)//第一次页面加载
            {
                LoadData(true);
            }
            //每次回发时从内存中取得数据源重新绑定,否则列头无法排序
            LoadData(false);
        }

        /// <summary>
        ///绑定空表头
        /// </summary>
        /// <param name="sender"></param>
        protected override void Render(HtmlTextWriter sender)
        {
            base.Render(sender);
        }

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            if (e.Parameter == "search")
            {
                //要定位的记录局编号
                string conBH = this.txtConBianHao.Text.Trim();
                int findIndex = PageTools.SearchRecordIndex(this.dtSource, this.gvList, "S_QUYUBH", conBH, false);
                if (findIndex == -1)
                {
                    e.Result = e.Parameter + "|-1|未找到对应数据！";
                }
                else
                {
                    e.Result = e.Parameter + "|0|success|" + findIndex;
                }
            }
            else if (e.Parameter == "info")
            {
                this._YS_JX_QUXIANBGS = this._YS_JX_QUXIANBGSBLL.SelectYS_JX_QUXIANBGS(id);
                e.Result = string.Join("|", e.Parameter, "0", "success",this._YS_JX_QUXIANBGS.S_QUYUBH,this._YS_JX_QUXIANBGS.S_QUYUMC,this._YS_JX_QUXIANBGS.S_MINGCHENG,this._YS_JX_QUXIANBGS.S_DIZHI,this._YS_JX_QUXIANBGS.S_YOUBIAN,this._YS_JX_QUXIANBGS.S_LIANXIDH,this._YS_JX_QUXIANBGS.S_ZHUBANR,this._YS_JX_QUXIANBGS.S_LIANXIR );
            }
            else if (e.Parameter == "del")
            {
                _YS_JX_QUXIANBGS = _YS_JX_QUXIANBGSBLL.SelectYS_JX_QUXIANBGS(id, null);
                this._YS_JX_QUXIANBGS.S_CAOZUOR = LoginInfo.CurrentUser.Account;
                this._YS_JX_QUXIANBGS.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
                this._YS_JX_QUXIANBGS.I_JLZT = -1;
                _SYS_LOGBLL.Log<YS_JX_QUXIANBGS>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "区县办公室", OperateState.Delete, _YS_JX_QUXIANBGS, null);
                if (_YS_JX_QUXIANBGSBLL.InsertOrUpdate(_YS_JX_QUXIANBGS, null))
                {
                    
                }
                e.Result = e.Parameter + "|0|操作成功！";
            }
            else if (e.Parameter == "saveValidate")
            {
                //判断编号是否重复
                if (_YS_JX_QUXIANBGSBLL.SelectYS_JX_QUXIANBGsDynamic(string.Format("S_QUYUBH='{0}' and ID<>{1}", this.txtQUYUBH.Text, id), null).Rows.Count > 0)
                {
                    e.Result = e.Parameter + "|-1|你所输入的名称,系统中已经存在使用过,请修改！";
                }
                else
                {
                    e.Result = e.Parameter + "|0|success！";
                }
            }
            else if (e.Parameter == "save")
            {
                OperateState operateState;                
                //添加
                if (id<=0)
                {
                    operateState = OperateState.Add;
                    _YS_JX_QUXIANBGS.ID = 0;
                    _YS_JX_QUXIANBGS.I_JLZT = 0;
                }
                //修改
                else
                {
                    //修改操作
                    operateState = OperateState.Modify;
                    _YS_JX_QUXIANBGS = _YS_JX_QUXIANBGSBLL.SelectYS_JX_QUXIANBGS(id, null);
                }
                _YS_JX_QUXIANBGS.S_DIZHI = this.txtDIZHI.Text;
                _YS_JX_QUXIANBGS.S_LIANXIDH = this.txtLIANXIDH.Text;
                _YS_JX_QUXIANBGS.S_LIANXIR = this.txtLIANXIR.Text;
                _YS_JX_QUXIANBGS.S_MINGCHENG = this.txtMINGCHENG.Text;
                _YS_JX_QUXIANBGS.S_QUYUBH = this.txtQUYUBH.Text;
                _YS_JX_QUXIANBGS.S_QUYUMC = this.txtQUYUMC.Text;
                _YS_JX_QUXIANBGS.S_YOUBIAN = this.txtYOUBIAN.Text;
                _YS_JX_QUXIANBGS.S_ZHUBANR = this.txtZHUBANR.Text;
                this._YS_JX_QUXIANBGS.S_CAOZUOR = LoginInfo.CurrentUser.Account;
                this._YS_JX_QUXIANBGS.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
                _SYS_LOGBLL.Log<YS_JX_QUXIANBGS>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "效区县办公室", operateState, _YS_JX_QUXIANBGS, null);
                if (_YS_JX_QUXIANBGSBLL.InsertOrUpdate(_YS_JX_QUXIANBGS, null))
                {
                   
                    e.Result = e.Parameter + "|0|保存成功！";
                }
            }
        }

        /// <summary>
        /// 加载列表
        /// </summary>
        protected void gvList_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e)
        {
            this.LoadData(true);
        }

        #endregion

        #region 方法
        
        /// <summary>
        /// 数据加载
        /// </summary>
        private void LoadData(bool reget)
        {
            if (reget)
            {
                this.dtSource = _YS_JX_QUXIANBGSBLL.SelectYS_JX_QUXIANBGsAll();
            }
            this.gvList.DataSource = this.dtSource;
            this.gvList.DataBind();
        }

        #endregion    
    }
}